package com.zhu.netty.heartbeat;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

public class HeartBeatClient {
    public static void main(String[] args) throws InterruptedException {
        ChannelFuture channelFuture = connect(9001,"127.0.0.1");
    }

    public static ChannelFuture connect(int port, String host) throws InterruptedException {
        EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
        Bootstrap b = new Bootstrap();
        b.group(eventLoopGroup)
                .channel(NioSocketChannel.class)
                .option(ChannelOption.TCP_NODELAY, true)
//                .option(ChannelOption.SO_KEEPALIVE, true)
                .handler(new RpcClientChannelInitializer());
        return b.connect(host,port).sync();
//        return b.connect(host,port).addListener((future) -> {
//            if (future.isSuccess()){
//                logger.info("Rpc客户端已启动 连接端口为{}",port);
//            }else {
//                logger.info("Rpc客户端启动失败 连接端口为{}！！！",port);
//            }
//        });
    }
}
